Skip to content

Add a fallible try_nested_case_when constructor - #11479

Open
ump45nose wants to merge 1 commit into
vortex-data:developfrom
ump45nose:fix/11425-try-nested-case-when
Open

ump45nose wants to merge 1 commit into
vortex-data:developfrom
ump45nose:fix/11425-try-nested-case-when

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

nested_case_when panics when it is given no WHEN/THEN pairs or more pairs than fit in a u32. Callers that build a CASE from user or query input (for example branches translated from SQL) had to repeat both checks before calling it, or wrap it to turn the panics into errors.

Changes

  • Add try_nested_case_when(when_then_pairs, else_value) -> VortexResult<Expression> in vortex-array/src/expr/exprs.rs, re-exported from vortex_array::expr. It returns an error for an empty pair list and for more than u32::MAX pairs.
  • nested_case_when now delegates to it and calls vortex_expect, the same pattern the bound_* constructors use, so its behaviour for valid input is unchanged and it still panics on invalid input. Its docs now point to the fallible variant.
  • Tests in scalar_fn/fns/case_when.rs: the empty case returns an error (with and without ELSE), the fallible constructor builds the same expression as nested_case_when, and nested_case_when still panics on empty input. Plus a doctest on try_nested_case_when.

bound_nested_case_when is left as is; happy to add a fallible bound variant too if you want one.

Tested with cargo test -p vortex-array --lib case_when (80 passed), the new doctest, cargo clippy -p vortex-array --all-targets --all-features -- -D warnings (clean) and cargo +nightly fmt --all --check.

AI assistance: this change was prepared with help from an AI coding assistant (agentic), and reviewed and submitted by me.

`nested_case_when` panics when it is given no WHEN/THEN pairs or more
pairs than fit in a `u32`. Callers that build a CASE from user or query
input had to repeat both checks or wrap the call to turn the panics into
errors.

Add `try_nested_case_when`, which returns an error in both cases, and
have `nested_case_when` delegate to it with `vortex_expect`, as the
`bound_*` constructors already do.

Fixes vortex-data#11425

Signed-off-by: Vincent <1729065730@qq.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant